<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>活动销课</title>
<meta name="renderer" content="webkit">	
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
<meta name="apple-mobile-web-app-status-bar-style" content="black">	
<meta name="apple-mobile-web-app-capable" content="yes">	
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/table.css">
</head>
<body>
	<div class="content-head">悦宝园会员管理系统</div>
	<div class="content-main">
		<div class="side-nav" ms-controller="navBar">
			<ul class="nav-item">
				<li><a href="main.html" class="nav-item-front nav-item-add">首页</a></li>
				<li ms-for="el in @navTitleArr">
					<a href="javascript:;" class="nav-item-front">{{el.par}}</a>
					<dl class="nav-item-child">
						<dd ms-for="($index, ex) in el.child"><a ms-attr='{href: el.href[$index]}'>{{ex}}</a></dd>
					</dl>
				</li>
			</ul>
		</div>
		<div class="content bg-gray"  ms-controller="main">
			<div class="tab-content">
				<div class="tab-item">
					<div class="sub-main">
						<p class="sub-title"><i>活动销课</i></p>
						<div class="import-area">
							<div class="import-block">
								<span class="import-name">宝宝姓名：</span>
								<div class="import-input"><input type="text" maxlength="20" ms-duplex="@name" id="name" disabled="disabled"><span ms-html="@iconnect()"></span></div>
							</div>
							<div class="import-block">
								<span class="import-name">宝宝小名：</span>
								<div class="import-input"><input type="text" maxlength="20" ms-duplex="@nickName" id="nickName" disabled="disabled"></div>
							</div>
							<div class="import-block">
								<span class="import-name">出生日期：</span>
								<div class="import-input"><input type="date" maxlength="20" ms-duplex="@birthday" id="birthday" disabled="disabled"></div>
							</div>
							<div class="import-block">
								<span class="import-name">家长姓名：</span>
								<div class="import-input"><input type="text" maxlength="20" ms-duplex="@paName" id="paName" disabled="disabled"></div>
							</div>
							<div class="import-block">
								<span class="import-name">电话：</span>
								<div class="import-input"><input type="tel" maxlength="11" ms-duplex="@tel" id="tel" disabled="disabled"></div>
							</div>
							<div class="import-block">
								<span class="import-name">剩余课时数：</span>
								<div class="import-input"><input type="tel" maxlength="11" ms-duplex="@subClass()" id="tel" disabled="disabled"></div>
							</div>
							<div class="import-block">
								<span class="import-name">活动日期：</span>
								<div class="import-input"><input type="date" maxlength="20" ms-duplex="@activityDay" id="activityDay"></div>
							</div>
							<div class="import-block">
								<span class="import-name">耗课数：</span>
								<div class="import-input"><input type="number" maxlength="11" ms-duplex="@classNum" id="classNum"></div>
							</div>
							<div class="import-block">
								<span class="import-name"></span>
								<a href="javascript:;" class="import-btn" ms-on-click="@subForm">修改</a></div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
<script src="js/jq.js"></script>
<script src="js/avalon.js"></script>
<script src="js/main.js"></script>
<script>
(function() {
	var parName = baseFunc.getSessionData("jumppage");
	var dataObj = baseFunc.getStorageData("member", {flag: parName})[0];
	var obj = {};
	var copyObj = jQuery.extend(true, {}, dataObj);

	// var freeClass = (function() {
	// 	var freeObj = dataObj.freeClass,
	// 		ids = 0;
	// 	if(freeObj) {
	// 		for (var i = 0; i < freeObj.length; i++) {
	// 			ids += parseInt(freeObj[i].num);
	// 		};
	// 		return ids;
	// 	}
	// 	return ids;
	// })();

	var freeClassFunc = function(dataObj) {
		var freeObj = dataObj,
			ids = 0;
		if(freeObj) {
			for (var i = 0; i < freeObj.length; i++) {
				ids += parseInt(freeObj[i].num);
			};
			return ids;
		}
		return ids;
	};
	
	var vm = avalon.define({
	    $id: "main",
	    name: dataObj.name,
	    nickName: dataObj.nickName,
	    birthday: dataObj.birthday,
	    paName: dataObj.paName,
	    subClass: function() {
	    	var originNum = dataObj.classNum ? parseInt(dataObj.classNum.formal) : 0,
				freeClass = freeClassFunc(dataObj.freeClass ? dataObj.freeClass : ""),
				freeNum = 0;

			return originNum + freeClass;
	    },
	    tel: dataObj.tel,
	    classNum: 0,
	    iconnect: function() {
	    	if (dataObj.connect) {
	    		return "已关联" + dataObj.connect.flag.replace(/[0-9]/ig,"");
	    	};
	    	return "";
	    },
	    subForm: function() {
	    	obj.name = $.trim(this.name);
	    	obj.nickName = $.trim(this.nickName);
	    	obj.birthday = $.trim(this.birthday);
	    	obj.paName = $.trim(this.faName);
	    	obj.tel = $.trim(this.tel);
	    	obj.activityDay = $.trim(this.activityDay);
	    	obj.classNum = $.trim(this.classNum);

	    	var resObj = baseFunc.valide(obj),
	    		status = true;

	    	$(".valide").remove();

	    	if(!obj.activityDay) {
	    		baseFunc.alert("请输入活动日期");
	    		return;
	    	}

	    	if(obj.classNum == 0) {
	    		baseFunc.alert("请输入耗课数");
	    		return;
	    	}

	    	if(!dataObj.passClass) {
	    		dataObj.passClass = [];
	    	}

	    	dataObj.passClass.push({
				date: obj.activityDay,
				time: 0,
				className: "activity",
				classFullName:  "activity",
				num: obj.classNum
			});
	    	

	    	var subClass = parseInt(dataObj.classNum.formal),
	    		freeClass = parseInt(dataObj.classNum.free),
	    		classNum = parseInt(obj.classNum),
	    		tempObj = {};

	    	if(subClass - classNum < 0) {
	    		subClass = (subClass + freeClass) - classNum;
	    		tempObj = {
	    			formal: 0,
	    			free: subClass
	    		};
	    	} else {
	    		tempObj = {
	    			formal: subClass - classNum,
	    			free: dataObj.classNum.free
	    		};
	    	}
	    	dataObj.classNum = tempObj;
	    	baseFunc.editStorageData("member", dataObj);
	    	baseFunc.alert("销课成功", "green");

	    	setTimeout(function() {
	    		baseFunc.locationSkip("activityAllMember.html");
	    	}, 500);
	    }
	})
})();
</script>
</body>
</html>